define(function(require, exports, module){
	
	/**
     * @name CodeMirror
     * @class 一个强大的javascript开发的语法高亮显示引擎 。此处分装按模式加载和主题切换。现提供html/javascript/java三种模式，default/ambiance/eclipse/monokai四种主题
     */
	require('./lib/codemirror');
	require('./lib/codemirror.css');
	
	/* 加载插件 */
	require('./addon/display/placeholder');
	seajs.importStyle('.CodeMirror pre.CodeMirror-placeholder{ color: #999; }');
	
	/**
     * @name CodeMirror#loadMode
     * @function   
     * @desc 按模式加载，现提供html/javascript/java三种模式。
     * @param {String} modename
     * @example
     * define(function(require) {
     *     $(function() {
     *     //如果渲染的是dialog弹框内的textarea,需要延时250，否则（getBoundingClientRect引起）Line Numbers错位
     *     });
     * });
     */
	var loadMode = function(mode, callback){
		if(semi.utils.isEmpty(mode))return;
		if($.isArray(mode)){
			var _arr = [];
			for(var i=0; i<mode.length; i++){
				switch(mode[i]){
					case 'html':
						mode[i] = './mode/htmlmixed/htmlmixed.js';
						_arr.push('./mode/xml/xml.js', './mode/javascript/javascript.js');
						break;
					case 'javascript':
						mode[i] = './mode/javascript/javascript.js';
						break;
					case 'java':
						mode[i] = './mode/clike/clike.js';
						break;
					default: theme[i] = ''; break;
				}
			}
			require.async(mode.concat(_arr), callback);
			return;
		}
		switch(mode){
			case 'html':
				require.async(['./mode/javascript/javascript.js', './mode/xml/xml.js', './mode/htmlmixed/htmlmixed.js'], callback);
				break;
			case 'javascript':
				require.async('./mode/javascript/javascript.js', callback);
				break;
			case 'java':
				require.async('./mode/clike/clike.js', callback);
				break;
		}
	}
	
	/**
     * @name CodeMirror#changeTheme
     * @function   
     * @desc 主题切换，现提供default/ambiance/eclipse/monokai四种主题。
     * @param {Object} options
     * @example
     * define(function(require) {
     *     $(function() {
     *     });
     * });
     */
	var changeTheme = function(editor, theme){
		if(semi.utils.isEmpty(editor) || semi.utils.isEmpty(theme))return;
		switch(theme){
			case 'ambiance':
				require.async('./theme/ambiance.css');
				editor.setOption('theme', theme);
				break;
			case 'eclipse':
				require.async('./theme/eclipse.css');
				editor.setOption('theme', theme);
				break;
			case 'monokai':
				require.async('./theme/monokai.css');
				editor.setOption('theme', theme);
				break;
			default:
				editor.setOption('theme', 'default');
				break;
		}
	}
	
	return{
		load: loadMode,
		theme: changeTheme
	}
});